package view.billing;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import model.Kunde;

public class CustomerComboBoxRenderer extends JLabel implements
		ListCellRenderer {

	public CustomerComboBoxRenderer(){
		setOpaque(true);
        setHorizontalAlignment(LEFT);
        setVerticalAlignment(CENTER);
	}
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4145181086325031403L;

	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {
		
		 if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
        } else {
            setBackground(list.getBackground());
            setForeground(list.getForeground());
        }
        
        String text = value != null ? value.toString(): "";
        if(value instanceof Kunde){
        	Kunde k = (Kunde)value;
        	text = k.getVorname() +" "+k.getNachname();
        }
        
        setText(text);
        setFont(list.getFont());
 
        return this;
	}

}
